'use strict';

const {getDefaultModelConfig} = require("../../utils/common");
const {formatDate} = require("../../utils");
module.exports = app => {
  const { STRING, BIGINT, INTEGER, DATE, TINYINT } = app.Sequelize;
  return app.model.define('SystemUser', {
    id: {
      type: BIGINT,
      primaryKey: true,
      autoIncrement: true,
      comment: '用户ID'
    },
    username: {
      type: STRING(30),
      defaultValue: '',
      comment: '用户账号'
    },
    password: {
      type: STRING(100),
      defaultValue: '',
      comment: '密码'
    },
    nickname: {
      type: STRING(30),
      defaultValue: '',
      comment: '用户昵称'
    },
    role: {
      type: TINYINT(4),
      defaultValue: 1, // 1 管理员 2 供应商
      comment: '角色'
    },
    email: {
      type: STRING(50),
      defaultValue: '',
      comment: '用户邮箱'
    },
    mobile: {
      type: STRING(11),
      defaultValue: '',
      comment: '手机号码'
    },
    avatar: {
      type: STRING(512),
      defaultValue: '',
      comment: '头像地址'
    },
    status: {
      type: INTEGER,
      defaultValue: 1,
      comment: '帐号状态（1正常 0停用）'
    },
    lastLoginTime: {
      type: DATE,
      comment: '最后登录时间',
      field: 'last_login_time',
      get() {
        return formatDate(this.getDataValue('lastLoginTime'), 'YYYY-MM-DD HH:mm:ss');
      }
    },
    ...getDefaultModelConfig(app)
  }, {
    tableName: 'system_users',
    timestamps: false, // 不使用Sequelize的默认时间戳字段
  });
};
